//index.js
//获取应用实例
const app = getApp()
const db = wx.cloud.database();
Page({
  todetail(e){
    let postid = e.currentTarget.dataset.id;
    console.log(postid)
    wx.navigateTo({
      url: '../blog/blog?id='+postid,
    })
  },
  getsepc(e){
    
    this.setData({
      spectype:e.currentTarget.dataset.spec,
      vis:true
    },()=>{
      let spec = this.data.spectype;
     // console.log(spec)
      wx.cloud.callFunction({
        name:'spec',
        data:{
          spectype:spec
        },
        success:res=>{
          console.log(res)
          this.showModal();
          this.setData({
            postList:res.result.data,
            vis:false
          })
        },
        fail:res=>{
          console.log(res)
        }
      })
    })
  },
  newspec(){
    //spectype
    wx.navigateTo({
      url: '../post/post?spectype='+this.data.spectype,
    })
  },
  onLoad(){
    console.log(app.globalData.admin)
    wx.request({
      url: 'https://lib.apisev.cn/config/spec.json',
      success:res=>{
        console.log(res)
        this.setData({
          SepcList:res.data.specgroup,
          admin:app.globalData.admin
        })
      }
    })
  },
  data: {
    vis:false,
    postList:[],
    spectype:'',
    admin:app.globalData.admin,
    SepcList:[],
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    TabCur: 1,
    scrollLeft: 0
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  showModal(e) {
    this.setData({
      modalName: 'viewModal'
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  tabSelect(e) {
    console.log(e);
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
  }
})
